<?php
/**
 * 常用的正则表达rules
 * Enter description here ...
 * @author nijn
 *
 */
class PregRules {

	/**
	 * 身份证格式验证
	 * Enter description here ...
	 * @param unknown_type $attribute
	 * @param unknown_type $message
	 */
	static function idCardsRules($attribute, $message = '身份证格式有误') {
		return self::returnRuels($attribute, $message, '/(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$)/');
	}
	
	/**
	 * 邮编格式验证
	 * Enter description here ...
	 * @param string $attribute
	 * @param string $message
	 */
	static function zipCodeRules($attribute, $message = '邮编格式有误') {
		return self::returnRuels($attribute, $message, '/^[0-9]\d{5}$/');	
	}
	
	/**
	 * 固定电话验证格式
	 * Enter description here ...
	 * @param string $attribute
	 * @param string $message
	 */
	static function  telephoneRules($attribute, $message = '电话格式有误,正确格式为：010-62266296') {
		return self::returnRuels($attribute, $message, '/(^((0\d{2})-)?(\d{7,8})$)|(^((0\d{3})-)?(\d{7,8})$)|(^(0\d{2})-(\d{7,8})-(\d+)$)|(^(0\d{3})-(\d{7,8})-(\d+)$)/');
	}
	
	/**
	 * 手机验证格式
	 * Enter description here ...
	 * @param string $attribute
	 * @param string $message
	 */
	static function phoneRules($attribute, $message = '手机格式有误') {
		return self::returnRuels($attribute, $message, '/^0{0,1}(13[0-9]|15[7-9]|15[0-2]|153|156|18[0-9])[0-9]{8}$/');
	}
	
	static function returnRuels($attribute, $message, $pattern) {
		
		return array($attribute, 
			'match', 
			'pattern'=>$pattern,
			'message'=>$message
		);
	}
}

?>